import App from './App'
import store from './store'

import plugin from './js_sdk/uni-admin/plugin'
import messages from './i18n/index.js'
import "./static/styles/reset.css"; // 引入样式初始化
// #ifndef VUE3
import Vue from 'vue'
import axios from 'axios'
import VueI18n from 'vue-i18n'
Vue.config.productionTip = false
Vue.use(VueI18n)
Vue.prototype.axios = axios;
// 引入element组件
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

//封装云函数请求
Vue.prototype.request = function(action, data) {
	return uniCloud.callFunction({
		name: 'router',
		data: {
			action,
			data
		}
	}).then(({
		result
	}) => {
		console.log(result);
		//后置守卫
		
		if(result.code.toString().indexOf('302')!=-1&&action!='common/user/checkToken'){
			uni.reLaunch({
				url:'/pages/login/login',
				fail(e) {
					console.log(e);
				}
			})
		}
		
		return Promise.resolve(result)
	}).catch(err => {
		uni.showModal({
			content: err.message || '请求服务失败',
			showCancel: false
		})
		return Promise.reject(err)
	})
}

// 通过选项创建 VueI18n 实例
const i18n = new VueI18n({
  locale: 'zh-Hans', // 设置地区
  messages, // 设置地区信息
})
Vue.use(plugin)
App.mpType = 'app'
const app = new Vue({
  i18n,
  store,
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import { createI18n } from 'vue-i18n'
const i18n = createI18n({
	locale: 'zh-Hans',
	messages
})
export function createApp() {
  const app = createSSRApp(App)
  app.use(i18n)
  app.use(plugin)
  app.use(store)
  return {
    app
  }
}
// #endif
